/**
 * 给定数组A和B，数组A的顺序可调，问Ai-Bi的绝对值的最小值是多少
 * 将A排序，对每个Bi，找最靠近的值计算一下即可
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

template<typename T>
void input(vector<T> & v, int n){
	v.assign(n + 1, {});
	for(int i=1;i<=n;++i) cin >> v[i];
	return;
}

using Real = long double;
using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;

int N;
vi A, B;

void proc(){
	set<int> ss(B.begin()+1, B.end());
	int cha = INT32_MAX;
	int b = -1, a = -1;
	for(int i=1;i<=N;++i){
        auto p = ss.equal_range(A[i]);
		if(p.first != p.second){
			cha = 0;
			a = b = A[i];
			break;
		}

		if(p.first != ss.end()){
			auto tmp = *p.first - A[i];
			if(tmp < cha){
                cha = tmp;
				a = A[i];
				b = *p.first;
			}
		}

		if(p.first != ss.begin()){
			--p.first;
			auto tmp = A[i] - *p.first;
			if(tmp < cha){
				cha = tmp;
				a = A[i];
				b = *p.first;				
			}
		}
	}

    int kb = 0;
	for(int i=1;i<=N;++i){
		if(b == B[i]){
            kb = i; break;
		}
	}

	int ka = 1;
	while(ka <= N and A[ka] != a) ++ka;
    assert(ka <= N);

	swap(A[ka], A[kb]);
	for(int i=1;i<=N;++i) cout << A[i] << " ";
	cout << endl;
}

void work(){
    cin >> N;
	input(A, N);
	input(B, N);
	
	proc();

	return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--) work();
    return 0;
}